/**
 * 文件描述如下：
 * 1. 设备驱动页面的数据
 */

const dataParams = {
  'device-driver-rsu': [
    { id: 0, key: 'ip', parentNode: null, name: 'IP地址', showType: 'input', inputType: 'ip' },
    { id: 1, key: 'local-ip', parentNode: null, name: '本地IP地址', showType: 'input', inputType: 'ip' },
    { id: 2, key: 'local-port', parentNode: null, name: '本地端口', showType: 'input', inputType: 'uint' },
    { id: 3, key: 'port', parentNode: null, name: '端口', showType: 'input', inputType: 'uint' },
  ],
  'device-driver-radar': [
    { id: 0, key: 'ip', parentNode: null, name: 'IP地址', showType: 'input', inputType: 'ip' },
    { id: 1, key: 'local-ip', parentNode: null, name: '本地IP地址', showType: 'input', inputType: 'ip' },
    { id: 2, key: 'local-port', parentNode: null, name: '本地端口', showType: 'input', inputType: 'uint' },
    { id: 3, key: 'port', parentNode: null, name: '端口', showType: 'input', inputType: 'uint' },
  ],
  'device-driver-traffic-light': [
    { id: 0, key: 'ip', parentNode: null, name: 'IP地址', showType: 'input', inputType: 'ip' },
    { id: 1, key: 'local-port', parentNode: null, name: '本地端口', showType: 'input', inputType: 'uint' },
    { id: 2, key: 'port', parentNode: null, name: '端口', showType: 'input', inputType: 'uint' },
    { id: 3, key: 'protocol', parentNode: null, name: 'protocol', showType: 'input', inputType: 'text' },
  ],
  'device-driver-cloud': [
    { id: 0, key: 'ip', parentNode: 'mqtt', name: 'ip', showType: 'input', inputType: 'ip' },
    { id: 1, key: 'mecid', parentNode: 'mqtt', name: 'mecid', showType: 'input', inputType: 'text' },
    { id: 2, key: 'port', parentNode: 'mqtt', name: 'port', showType: 'input', inputType: 'uint' },
    { id: 3, key: 'sub-from-cloud-topics', arr: [], parentNode: 'mqtt', name: 'sub-from-cloud-topics', showType: 'arr', inputType: 'number' },
    { id: 4, key: 'sub-from-dev-topics', arr: [], parentNode: 'mqtt', name: 'sub-from-dev-topics', showType: 'arr', inputType: 'ip' },

    { id: 5, key: 'to-dev-mqtt-ip', parentNode: 'mqtt', name: 'sto-dev-mqtt-ip', showType: 'input', inputType: 'ip' },
    { id: 6, key: 'to-dev-mqtt-port', parentNode: 'mqtt', name: 'to-dev-mqtt-port', showType: 'input', inputType: 'uint' },

    { id: 0, key: 'ip', parentNode: 'tcp', name: 'tcp-ip', showType: 'input', inputType: 'ip' },
    { id: 1, key: 'port', parentNode: 'tcp', name: 'tcp-port', showType: 'input', inputType: 'uint' },
  ],
}

export const dataProcessing_devicedriver = (params, type) => {
  if (!params) return
  // 头部的块
  //  data_main = []
  const data_main = dataParams[type]
  data_main.forEach((item) => {
    item.value = item.parentNode ? params[item.parentNode][item.key] : params[item.key]
    if (item.arr) item.arr = params[item.parentNode][item.key]
  })

  return { data_main }
}
